
//
//  UIImage+ScaleImage.swift
//  添加视图辅助开发
//
//  Created by 鱼龙之梦 on 15/9/10.
//  Copyright © 2015年 panyanzhi. All rights reserved.
//
import UIKit
extension UIImage {
    func scaleImageToWidth(width:CGFloat)->UIImage{
        if size.width < width{
           return self
        }
        let height = width * size.height/size.width
        
        //注意：用画图得到指定大小图片
        let s = CGSize(width: width, height: height)
        UIGraphicsBeginImageContext(s)
        
        drawInRect(CGRect(origin: CGPointZero, size: s))
        
        let reuslt = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return reuslt
    }
}
